<html>
	<head>
		<link rel="stylesheet" type="text/css" href="stylize2.css" />
	</head>
	
	<body>
		<div id = "firstBar">
			<!--<img src = "Logopl.png">-->
		</div>
	
		<div id = "menu">
			<ul>
				<li><a href = "Homepage.php">Home</a></li>
				<li><a href = "fuses.php">Fuses</a></li>
				<li><a href = "myboard.php">MyBoard</a></li>
			</ul>
		</div>

		<?php
		$username = "";
		$password = "";
		$con = mysql_connect("localhost","root","$username","$password");
				if (!$con)
				{
					die('Could not connect: ' . mysql_error());
				}
		
		mysql_select_db("rgfusion", $con);

		$loginGood = false;

		if(array_key_exists("user",$_COOKIE))
		{
			$cookieData = explode(",", $_COOKIE['user']);
			if(count($cookieData) == 2)
			{
				$userId = $cookieData[0];
				$encPw = $cookieData[1];
				$sql="SELECT * FROM users WHERE Id=$userId AND password='$encPw'";
				$result=mysql_query($sql, $con);
				if($result && mysql_num_rows($result) == 1)
				{
					$row = mysql_fetch_array($result);
					$loginGood = true;
				}
			}
		}
		?>
		<div id = "secondBar">
			<?php
		
			if($loginGood)
			{
				setcookie('user',$_COOKIE['user'],time() + 31449600);
				echo "Welcome" . $row["Username"];
				?>
				<a href = "logout.php">Logout</a>
			<?php
			}
			else if(!(isset($hideLogin) && $hideLogin))
			{
			?>
				<form name="form1" method="post" action="checklogin.php" style="display: inline-block;">
					<label for="myusername">Username: </label><input name="myusername" type="text" id="myusername">
					<label for="mypassword">Password: </label><input name="mypassword" type="password" id="mypassword">
					<input name="Submit" type="submit" value="Login">
				</form>
				<a style="float:right;" href = "register.php">Register</a>
			<?php
			}
			?>
		</div>	